#ifndef UDPWORK_H
#define UDPWORK_H

#define MSG_HEADER_LENGTH 4
#define MSG_TOTAL_LENGTH 4
#define MSG_TYPE_LENGTH 4
#define MSG_STREAM_LENGTH 4

#include <QObject>
#include <QPointer>
#include <QUdpSocket>
#include <QPixmap>


class UDPWork : public QObject
{
    Q_OBJECT
public:
    explicit UDPWork(QObject *parent = nullptr);

    void send_broadCast();

    void send_commamd(QString command);

    void send_Recvshakehands(QString ip);

    int unpack_receive_data(const QByteArray &bytes);

    void handle_Command_message(const QByteArray &bytes);

    void handle_preview_message(const QByteArray &bytes);

    void handle_Recvshakehand_message(const QByteArray &bytes);

    void handle_shakehand_message();

    QString GetLocalIP();

signals:
    void update_textBrowser_signal(QString data);

    void detain_ClientIP_signal(QString data);

    void preview_image_signal(QPixmap img);

public slots:
    void send_Message_slot(QString data);

    void send_Broadcast_slot();

    void receive_data_slot();

    void Update_IP_slot(QString ip);

private:
    QPointer<QUdpSocket> udp_socket;
    QHostAddress localAddress;
    QHostAddress remoteAddress;

    QString localIP;
    QByteArray receive_bytes;

};

#endif // UDPWORK_H
